package com.feng.financial.manager.service;

import com.feng.financial.api.event.ProductStatusEvent;
import com.feng.financial.entity.ProductEntity;
import com.feng.financial.entity.enums.ProductStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author Administrator
 */
@Slf4j
@Component
public class ChangeProductStatus {

    static final String MQ_DESTINATION = "VirtualTopic.PRODUCT_STATUS";

    @Autowired
    private JmsTemplate jmsTemplate;

    public void changeStatus(String id, ProductStatus status){
        ProductStatusEvent event = new ProductStatusEvent(id,status);
        log.info(event.toString());
        jmsTemplate.convertAndSend(MQ_DESTINATION,event);
    }

    @PostConstruct
    public void init(){
        changeStatus("1",ProductStatus.IN_SELL);
    }

}
